import Mock from 'mockjs'



let List = [
  { username: 'admin', password: 'admin', nickname:'黎忆南', token: Mock.Random.guid(),imgUrl:'https://www.qqkw.com/d/file/p/2018/06-27/38c5472cb87fa8edb2cb700ffdc3607e.jpg' },
  { username: '111', password: '111', nickname:'赵尚', token: Mock.Random.guid(), imgUrl:'https://pic4.zhimg.com/50/v2-893d14370b098a81e69c23ae28b3efc8_hd.jpg?source=1940ef5c' }
]

export default {
  getLogin:config=>{
    const { username, password } = JSON.parse(config.body)
    const exictUser = List.filter(item=>item.username == username)[0]
    if(exictUser && password == exictUser.password){
      return {
        code: 200,
        message: 'success',
        data:exictUser
      }
    }else{
      return {
        code: 201,
        message: 'fail'
      }
    }
  },
  updatePwd: config => {
    const { old_pwd, new_pwd } = JSON.parse(config.body)
    List.some(item => {
      if (item.username === username) {
        item.password = new_pwd
        return true
      }
    })
    return {
      code: 20000,
      data: {
        message: '编辑成功'
      }
    }
  }
}
